package com.ruoyi.web.controller.system;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.annotation.PropertyInject;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.enums.InjectType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.order.domain.Area;
import com.ruoyi.order.service.IAreaService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 片区管理Controller
 *
 * @author ruoyi
 * @date 2021-07-10
 */
@Api("片区管理")
@RestController
@RequestMapping("/system/area")
public class AreaController extends BaseController
{
    @Autowired
    private IAreaService areaService;

    /**
     * 查询片区管理列表
     */
    @ApiOperation("获取片区列表")
    @PreAuthorize("@ss.hasPermi('system:area:list')")
    @GetMapping("/list")
    public TableDataInfo list(Area area)
    {
        startPage();
        List<Area> list = areaService.selectAreaList(area);
        return getDataTable(list);
    }

    /**
     * 导出片区管理列表
     */
    @ApiOperation("导出片区列表")
    @PreAuthorize("@ss.hasPermi('system:area:export')")
    @Log(title = "片区管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Area area)
    {
        List<Area> list = areaService.selectAreaList(area);
        ExcelUtil<Area> util = new ExcelUtil<Area>(Area.class);
        return util.exportExcel(list, "片区管理数据");
    }

    /**
     * 获取片区管理详细信息
     */
    @ApiOperation("获取片区详细信息")
    @PreAuthorize("@ss.hasPermi('system:area:query')")
    @GetMapping(value = "/{areaId}")
    public AjaxResult getInfo(@PathVariable("areaId") Long areaId)
    {
        return AjaxResult.success(areaService.selectAreaById(areaId));
    }

    /**
     * 新增片区管理
     */
    @ApiOperation("新增片区")
    @PreAuthorize("@ss.hasPermi('system:area:add')")
    @Log(title = "片区管理", businessType = BusinessType.INSERT)
    @PostMapping
    @PropertyInject(type = InjectType.Insert)
    public AjaxResult add(@RequestBody Area area)
    {
        return toAjax(areaService.insertArea(area));
    }

    /**
     * 修改片区管理
     */
    @ApiOperation("修改片区")
    @PreAuthorize("@ss.hasPermi('system:area:edit')")
    @Log(title = "片区管理", businessType = BusinessType.UPDATE)
    @PutMapping
    @PropertyInject(type = InjectType.Update)
    public AjaxResult edit(@RequestBody Area area)
    {
        return toAjax(areaService.updateArea(area));
    }

    /**
     * 删除片区管理
     */
    @ApiOperation("删除片区")
    @PreAuthorize("@ss.hasPermi('system:area:remove')")
    @Log(title = "片区管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{areaIds}")
    public AjaxResult remove(@PathVariable String[] areaIds)
    {
        return toAjax(areaService.deleteAreaByIds(areaIds));
    }
}
